package org.csu.mypetstorecmsapi.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseResponse <T>{

    private final int statusCode;
    private final String message;
    private T data;

    private BaseResponse(int statusCode, String message){
        this.statusCode = statusCode;
        this.message = message;
    }
    private BaseResponse(int statusCode, String message, T data){
        this.statusCode = statusCode;
        this.message = message;
        this.data = data;
    }

    @JsonIgnore
    public boolean isSuccess(){
        return this.statusCode == ResponseCode.SUCCESS.getCode();
    }

    public static <T>BaseResponse<T> createForSuccess(){
        return new BaseResponse<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc());
    }

    public static <T>BaseResponse<T> createForSuccess(String message){
        return new BaseResponse<T>(ResponseCode.SUCCESS.getCode(), message);
    }

    public static <T>BaseResponse<T> createForSuccess(T data){
        return new BaseResponse<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc(), data);
    }

    public static <T>BaseResponse<T> createForError(){
        return new BaseResponse<T>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDesc());
    }

    public static <T>BaseResponse<T> createForError(String message){
        return new BaseResponse<T>(ResponseCode.ERROR.getCode(), message);
    }

    public static <T>BaseResponse<T> createForError(int statusCode, String message){
        return new BaseResponse<T>(statusCode, message);
    }
}
